package com.lingnan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lingnan.mapper.JoinedActiveMapper;
import com.lingnan.mapper.SelfActiveMapper;
import com.lingnan.pojo.Active;
import com.lingnan.pojo.JoinedActive;
import com.lingnan.pojo.SelfActive;
import com.lingnan.service.ApplyService;
import com.lingnan.service.JoinedActiveService;
import com.lingnan.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
/**
 * @Author 梁兴达
 * @Date 2022/3/27 13:01:42
 * @Version 1.0
 */
@Service
public class JoinedActiveServiceImpl extends ServiceImpl<JoinedActiveMapper,JoinedActive> implements JoinedActiveService {

    @Autowired
    private SelfActiveMapper selfActiveMapper;

    @Autowired
    private ApplyService applyService;


    @Override
    public JoinedActive findAllByNo(UserVo userVo) {
        JoinedActive joinedActive = new JoinedActive();

        //查询招募表活动
        QueryWrapper<SelfActive> wrapper = new QueryWrapper<>();
        wrapper.eq("no",userVo.getNo());
        LocalDate now = LocalDate.now();
        String endTime = now.format(DateTimeFormatter.ISO_DATE); //2022-03-26
        //小于今天
        wrapper.lt("end_time",endTime);
        List<SelfActive> selfActives = selfActiveMapper.selectList(wrapper);
        joinedActive.setSelfActives(selfActives);

        //查询个人已报名活动
        List<Active> actives = applyService.findJoinedByNo(userVo);
        joinedActive.setActives(actives);

        return joinedActive;
    }
}
